package cliu.TutorialOnImages;

/*
 * MyImageView.java
 * 
 * [AUTHOR]: Chunyen Liu
 * [SDK   ]: Android SDK 2.1 and up
 * [NOTE  ]: http://www.developer.com/ws/other/article.php/3748281/Working-with-Images-in-Googles-Android.htm
 */

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.widget.ImageView;


class MyImageView extends ImageView {
	Bitmap mBitmap;        
	Canvas mCanvas;    

	public MyImageView(Context c) {
		super(c);                                     
	}   

	@Override
	public void setImageBitmap(Bitmap bm) {                                   
		mBitmap = bm;                       
		super.setImageBitmap(bm);           
	}               

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		int curW = mBitmap != null ? mBitmap.getWidth() : 0;
		int curH = mBitmap != null ? mBitmap.getHeight() : 0;
		if (curW >= w && curH >= h)
			return;            

		if (curW < w) curW = w;
		if (curH < h) curH = h;

		Bitmap newBitmap = Bitmap.createBitmap(curW, curH, Bitmap.Config.ARGB_8888);
		Canvas newCanvas = new Canvas();
		newCanvas.setBitmap(newBitmap);          
		if (mBitmap != null) {
			newCanvas.drawBitmap(mBitmap, 0, 100, null);
		}
		mBitmap = newBitmap;
		mCanvas = newCanvas;
	}                	      

	@Override
	protected void onDraw(Canvas canvas) {	    
		if (mBitmap != null) 
			canvas.drawBitmap(mBitmap, 0, 0, null);

		mCanvas = canvas;                      
	}       
}